package com.eonmind.common.provider.entity.user;

import com.eonmind.common.contract.enums.user.UserLoginStatus;
import com.eonmind.common.contract.timer.Timer;
import com.mongoplus.annotation.ID;
import com.mongoplus.annotation.collection.CollectionName;
import com.mongoplus.enums.IdTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;


/**
 * 用户登录记录实体类
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@CollectionName("userLoginRecords")
@FieldNameConstants
public class UserLoginRecord {
    /**
     * 主键ID
     */
    @ID(type = IdTypeEnum.AUTO)
    private Long id;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 登录时间
     */
    private Long loginTime = Timer.currentTimestamp();

    /**
     * 登录IP
     */
    private String loginIp;

    /**
     * 登录地点
     */
    private String loginLocation;

    /**
     * 登录设备
     */
    private DeviceInfo loginDevice;

    /**
     * 登录状态(0-失败 1-成功)
     */
    private Integer loginStatus = UserLoginStatus.SUCCESS.getCode();

    @Data
    public static class DeviceInfo {
        private String operatingSystem;
        private String osVersion;
        private String browser;
        private String browserVersion;
        private String deviceType;
        

        @Override
        public String toString() {
            return String.format("OS: %s %s, Browser: %s %s, Device: %s",
                    operatingSystem, osVersion, browser, browserVersion, deviceType);
        }
    }

}